<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>编辑用户</title>
    <script type="text/javascript">
      Ext.onReady(function(){
        var articleId = Ext.create('Ext.form.field.Hidden', {
          name: 'id'
        });
        
        var title = Ext.create('Ext.form.field.Text', {
          fieldLabel: '标题',
          allowBlank: false,
          blankText: "标题不能为空",
          name: 'title',
          anchor: '95%'
        });

        var content = new Ext.form.HtmlEditor({
          fieldLabel: '内容',
          name: 'content',
          height:385,
          anchor: '100%'
        });

        var articleSubTypeStore = Ext.create('Ext.data.ArrayStore', {
          //fields: ['value', 'text'],
          fields: ['text'],
          data : articleSubTypeArray
        });

        var articleSubType = Ext.create('Ext.form.ComboBox', {
          fieldLabel: '文章类型',
          store: articleSubTypeStore,
          valueField:'text',
          displayField:'text',
          allowBlank: false,
          typeAhead: true,
          mode: 'local',
          
          
          name:'sub_type',
          emptyText:'选择文章类型...',
          //allowBlank: false,
          anchor: '95%'
        });

        //提交按钮
        var submitButton = Ext.create('Ext.Button', {
          text: '提交',
          iconCls: 'icon-save',
          handler: function(){
            if (editArticleForm.form.isValid()) {
              this.disable();
              editArticleForm.form.submit({
                method: 'GET',
                success: function(result, response){
                  if (response.result.info == "成功") {
                    //添加成功后，隐藏窗口，并刷新Grid
                    editArticleWin.destroy();
                  }
                  else {
                    Ext.MessageBox.alert('消息', response.result.info);
                  }
                },
                failure: function(result, response){
                  Ext.MessageBox.alert('提示', result.responseText);
                }
              });
            }
            else {
              Ext.MessageBox.alert('错误提示', '请按要求填写必输选项.');
            }
          }
        })

        //暂时保存按钮
        var closeButton = Ext.create('Ext.Button', {
          text: '关闭',
          tooltip: '关闭当前窗口，并且当前编辑的信息不能保存。',
          iconCls: 'exit',
          handler: function(){
            editArticleWin.destroy();
          }
        });
        //提交按钮
        var submitButton = Ext.create('Ext.Button', {
          text: '提交',
          iconCls: 'icon-save',
          handler: function(){
            if (editArticleForm.form.isValid()) {
              editArticleForm.form.submit({
                method: 'GET',
                success: function(result, response){
                  if (response.result.info == "成功") {
                    //添加成功后，隐藏窗口，并刷新Grid
                    editArticleWin.destroy();
                  }
                  else {
                    Ext.MessageBox.alert('消息', response.result.info);
                  }
                },
                failure: function(result, response){
                  Ext.MessageBox.alert('提示', result.responseText);
                }
              });
            }
            else {
              Ext.MessageBox.alert('错误提示', '请按要求填写必输选项.');
            }
          }
        })

        //暂时保存按钮
        var closeButton = Ext.create('Ext.Button', {
          text: '关闭',
          tooltip: '关闭当前窗口，并且当前编辑的信息不能保存。',
          iconCls: 'exit',
          handler: function(){
            editArticleWin.destroy();
          }
        });
        
        var editArticleForm = Ext.create('Ext.form.Panel', {
          fieldDefaults: {
            labelWidth: 55,
            labelAlign: 'right'
          },
          frame:true,
          url: '/article/update?id=' + articleId,
          reader: new Ext.data.JsonReader({
            root: 'root'
          }, [{
              name: 'id'
            }, {
              name: 'title'
            }, {
              name: 'content'
            }, {
              name: 'sub_type'
            }]),
          bodyStyle:'padding:5px 5px 0',
          width: 800,
          //height:300,
          items: [{
              layout: 'column',
              xtype: 'container',
              items: [{
                  columnWidth: .8,
                  layout: 'anchor',
                  xtype: 'container',
                  items: [title]
                },{
                  columnWidth: .2,
                  layout: 'anchor',
                  xtype: 'container',
                  items: [articleSubType]
                }]
            },content,articleId],
          buttons: [submitButton,closeButton]
        });
        //编辑前，把数据引入到表单中。
        // load form and assign value to fields
        editArticleForm.form.load({
          url: '/article/getArticleById?id=<%=params[:id]%>',
          method : 'GET',
          waitMsg: '正在载入数据...',
          success: function(form, action){
          },
          failure: function(form, action){
            Ext.MessageBox.alert('提示信息', '信息加载失败');
          }
        });
            
        editArticleForm.render('edit_article_form');
      })
    </script>
  </head>
  <body>
    <div id="edit_article_form"></div>
  </body>
</html>
